//
//  SGHttpRequest.m
//  SemiGroup
//
//  Created by 陈无忌 on 12/9/15.
//  Copyright © 2015 陈无忌. All rights reserved.
//

#import "SGHttpRequest.h"

@implementation SGHttpRequest

+ (void)SGPOST:(NSString *)URLString
    parameters:(NSMutableDictionary *)parameters
       success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
       failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure{
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/plain",@"text/html", nil]];
    
    // 如果传过来的参数是nil或其他，那么实例化一NSMutableDictionary
    if (!parameters || ![parameters isKindOfClass:[NSMutableDictionary class]]) {
        parameters = [[NSMutableDictionary alloc] init];
    }
    [manager POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            success(operation,responseObject);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(operation,error);
        }
    }];
}

@end
